// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import Vue from 'vue'
// import FastClick from 'fastclick'
import App from './App'
import router from './router'
import {Ajax} from "./service/ajax"
import {Storage} from "./service/storage"
import './common/rem'
import "./assets/font/iconfont.css";
import {webUrl} from "./common/base.js"
import noData from './components/no-data.vue'
import Store from './store'
// import Raven from 'raven-js';
// import RavenVue from 'raven-js/plugins/vue';
// import VueLazyload from 'vue-lazyload'

import {
  XHeader,
  Checklist,
  XButton,
  Group,
  XDialog,
  TransferDom,
  XInput,
  Flexbox,
  FlexboxItem,
  CheckIcon,
  Tab,
  TabItem,
  XNumber,
  XTable,
  Swiper,
  Popup,
  Confirm,
  Previewer,
  SwiperItem,
  Search,
  Selector
} from 'vux'

Vue.component('x-button', XButton)
Vue.component('x-header', XHeader)
Vue.component('x-input', XInput)
Vue.component('group', Group)
Vue.component('checklist', Checklist)
Vue.component('x-dialog', XDialog)
Vue.directive('transfer-dom', TransferDom)
Vue.component('flexbox', Flexbox)
Vue.component('flexbox-item', FlexboxItem)
Vue.component('check-icon', CheckIcon)
Vue.component('tab', Tab)
Vue.component('tab-item', TabItem)
Vue.component('x-number', XNumber)
Vue.component('x-table', XTable)
Vue.component('swiper', Swiper)
Vue.component('popup', Popup)
Vue.component('confirm', Confirm)
Vue.component('previewer', Previewer)
Vue.component('swiper-item', SwiperItem)
Vue.component('Search', Search)
Vue.component('no-data', noData)
Vue.component('Selector', Selector)

import VueScroller from 'vue-scroller'
Vue.use(VueScroller)
import {ToastPlugin} from 'vux'
Vue.use(ToastPlugin)

import {ConfigPlugin, ConfirmPlugin} from 'vux'
Vue.use(ConfigPlugin, {
  $layout: 'VIEW_BOX'
})
Vue.use(ConfirmPlugin)

// 使用VueLazyload并传入相应的配置
Vue.use(VueLazyload)

Vue.prototype.$devicePixelRatio = 2
Vue.prototype.$webUrl = webUrl;
Vue.prototype.$ajax = Ajax;
Vue.prototype.$storage = Storage;
//分页条数处理
Vue.prototype.$rows = 20;
//弹窗滑动穿透处理
Vue.prototype.ModalHelper = (function () {
  return {
    afterOpen: function () {
      var mo = function (e) {
        e.preventDefault()
      };
      document.getElementsByClassName("weui-mask")[0].addEventListener('touchmove', mo, false)// 禁止页面滑动
      document.getElementsByClassName("main")[0].style.overflow = 'hidden'
    },
    beforeClose: function () {
      var mo = function (e) {
        e.preventDefault()
      }
      document.getElementsByClassName("weui-mask")[0].removeEventListener('touchmove', mo, false)
      document.getElementsByClassName("main")[0].style.overflow = ''
    }
  }
}())

Vue.prototype.$checkPhone = function checkPhone(phone) {
  if (!(/^1\d{10}$/.test(phone))) {
    return false;
  } else {
    return true;
  }
}

Vue.prototype.$checkIsNumber = function checkIsNumber(str) {
  if (!(/^[1-9]{1}[\d]*$/.test(str))) {
    return false;
  } else {
    return true;
  }
}

Vue.prototype.$checkIsNumberContainZoro = function checkIsNumber(str) {
  if (!(/^[0-9]{1}[\d]*$/.test(str))) {
    return false;
  } else {
    return true;
  }
}

Vue.prototype.$getJson = function getJson(str) {
  return eval("(" + str + ")");
}

Vue.prototype.$getJsonAndroidOrIOS = function getJson(obj,key) {
  var u = navigator.userAgent, app = navigator.appVersion;
  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
  var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  try {
    if (isAndroid) {
      return JSON.parse(obj[key])
    } else if (isIOS) {
      return obj[key]
    }
  }catch (e) {
    // console.log("====e",e);
  }
}

Vue.prototype.$fromApp = function fromApp(that) {
   if (that.$route.query.from == 'app') {
     Storage.set("app", 1)
     if(that.$route.query.showTitle){
       return false;
     }
    return true;
  }
  return false
}

Vue.prototype.$transSpecial = function transSepecial(str) {
  str=str.replace(/\%/g,"%25");
  str=str.replace(/\#/g,"%23");
  str=str.replace(/\&/g,"%26");
  return str
}

Vue.prototype.$noData = function noData(arr) {
  if(arr&&arr.length>0){
      return "没有更多数据了"
  }
  return ""
}

Vue.prototype.$callJava = function getJson(obj) {
  var u = navigator.userAgent, app = navigator.appVersion;
  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
  var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  if (isAndroid) {
    //这个是安卓操作系统
    if (this.$fromApp(this)) {
      JSCallJava.callJava(JSON.stringify(obj));
    }
  } else if (isIOS) {
    //这个是ios操作系统
    if (this.$fromApp(this)) {
      window.webkit.messageHandlers.Param.postMessage(JSON.stringify(obj));
    }
  }
}

Vue.prototype.$platform = function getPlatform(){
  var u = navigator.userAgent, app = navigator.appVersion;
  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
  var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  if (isAndroid) {
      return 1
  } else if (isIOS) {
    return 2
  }else{
    return 3
  }
}



// console.log("====",process.env)
// Raven.config('https://7ccd7c5ad6894d799ffb403848bafdd6@sentry.io/1725128', {
//   autoBreadcrumbs: {
//     xhr: true,
//     console: true
//   },
//   release: "1.2"
// }).addPlugin(RavenVue, Vue).install()
if(process.env.NODE_ENV!=="development"){
    window.onerror = function (e) {
      Raven.captureException(e)
    }
    Vue.config.errorHandler = (err, vm, info) => {
      Raven.captureException(err)
    }
  }
Vue.directive("btn-control", {
  // 插入dom 时做的事情
  inserted: function(el, bind) {
    el.addEventListener("click", () => {
      el.disabled = true
      setTimeout(() => {
        el.disabled = false
      }, bind.value || 2000)
    });
  }
});

Vue.config.productionTip = false
new Vue({
  router,
  render: h => h(App),
  store: Store,
  data: {
    eventHub: new Vue()
  }
}).$mount('#app-box')
